package com.mjx.algorithm.oj;

import java.util.Scanner;

/**
 * 救济队列
 * Created by meijingxiang on 2017/2/9.
 */
public class problem1054 {
    public static void main(String[] args) {
        int[] peoples;
        int n,k,m;
        Scanner scanner = new Scanner(System.in);
        while (true){
            String s = scanner.nextLine();
            String[] temp = s.split(" ");
            n = Integer.parseInt(temp[0]);
            k = Integer.parseInt(temp[1]);
            m = Integer.parseInt(temp[2]);
            if (n == 0 && k == 0 && m == 0)
                break;
            peoples = new int[n];
            for (int i = 0; i < n; i++) {
                peoples[i] = 1;
            }
            int lastPos1 = 0;
            int lastPos2 = n - 1;
            while (true){
                int num1 = select1(peoples, k, lastPos1);
                int num2 = select2(peoples, m, lastPos2);
                if (num1 == -1 || num2 == -1)
                    break;
                lastPos1 = num1;
                lastPos2 = num2;
                peoples[num1] = peoples[num2] = 0;
                if (k%n != num1+1)
                    System.out.print(",");
                if (num1 == num2){
                    System.out.print((num1+1));
                }
                else
                    System.out.print((num1+1)+" "+(num2+1));
            }
            System.out.println();
        }
    }

    public static int select1(int[] array,int k,int lastPos){
        int step = 0;
        int i = lastPos;
        while (step <= k){
            if (i == array.length){
                int sum=0;
                for (int j = 0; j < array.length; j++) {
                    sum+=array[j];
                }
                if (sum == 0)
                    return -1;
                else
                    i = 0;
            }
            if (array[i] == 1){
                if (step + 1 == k)
                    return i;
                step++;
            }
            i++;
        }
        return -1;
    }

    public static int select2(int[] array,int m, int lastPos){
        int step = 0;
        int i = lastPos;
        while (step <= m){
            if (i == -1){
                int sum=0;
                for (int j = 0; j < array.length; j++) {
                    sum+=array[j];
                }
                if (sum == 0)
                    return -1;
                else
                    i = array.length - 1;
            }
            if (array[i] == 1){
                if (step + 1 == m)
                    return i;
                step++;
            }
            i--;
        }
        return -1;
    }
}
